package com.me.controller;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class TestController {
	private final Logger logger = Logger.getLogger(getClass());
	@Autowired
	private DiscoveryClient client;
	@Autowired
	private RestTemplate restTemplate;

	@GetMapping("/add")
	public String add(String name) {

		ServiceInstance serviceInstance = client.getLocalServiceInstance();
		logger.info("nihao" + System.currentTimeMillis());
		return name;
	}

	@GetMapping("/hi")
	public String hi(String name) {

		logger.info("calling trace wzn-2");
		return restTemplate.getForObject("http://localhost:8762/info", String.class);
	}

	@GetMapping("/miya")
	public String info() {
		logger.info("calling trace wzn-2 ");
		return "i'm server-2";

	}
	
}
